package com.cn.wanxi.servlet;

import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/newsDetail")
public class NewsDetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CommonServlet.getCompanyAndNavData(req);
//        得到页面的id
        String idString = req.getParameter("id");
//        将id转换位整型
        int id = Integer.parseInt(idString);
//        调用服务逻辑层
        NewsService newsService = new NewsService();
//        得到逻辑层返回过来的对象
        NewsModel newsModel = newsService.getNewsModelById(id);
//        将对象存储在request
        req.setAttribute("newsModel", newsModel);
//        页面转发
        req.getRequestDispatcher("/jsp/newsDetail.jsp").forward(req, resp);
    }
}
